<style type="text/css">
</style>

<div class="filter">
    <div class="f0 item" style="width: 100px;">
        <select data-am-selected>
            <option value="-1" selected>全部游戏</option>
        </select>
    </div>
    <div class="f1 item" style="width: 110px;">
        <input type="text" class="am-form-field" placeholder="会员账号" />
    </div>
    <div class="f2 item" style="width: 110px;">
        <input type="text" class="am-form-field" placeholder="起始日期" id="start"
            data-am-datepicker="{theme:'success'}" readonly required />
    </div>
    <div class="f3 item" style="width: 110px;">
        <input type="text" class="am-form-field" placeholder="结束日期" id="end"
            data-am-datepicker="{theme:'success'}" readonly required />
    </div>
    <div class="f4 item" style="width: 120px;">
        <input type="number" class="am-form-field" placeholder="最小输赢"  />
    </div>
    <div class="f5 item" style="width: 120px;">
        <input type="number" class="am-form-field" placeholder="最大输赢"  />
    </div>
    
    <div class="button item">
        <button type="button" class="am-btn am-btn-primary">查看</button>
    </div>
    <div class="clear"></div>
</div>
<div class="red clue" style="line-height: 36px;">
    【操作提示】实际输赢 = 投注输赢 + 返水 + 奖励金额 - 惩罚金额。（负数表示会员亏损，平台盈利）
</div>

<table class="am-table am-table-bordered am-table-radius am-table-striped am-table-compact" id="result-table" 
    style="min-width: 800px;">
    <thead>
    <tr>
        <th>用户名</th>
        <th>游戏</th>
        <th>姓名</th>
        <th>上级代理</th>
        <th>余额</th>
        <th>充值金额</th>
        <th>取款金额</th>
        <th>奖励金额</th>
        <th>惩罚金额</th>
        <th>其他扣款</th>
        <th>充值/取款笔数</th>
        <th>投注金额</th>
        <th>注单数</th>
        <th>中奖总额</th>
        <th>输赢(不含退水)</th>
        <th>返水</th>
        <th>实际输赢</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>

<div class="zxf_pagediv"></div>
<div style="height: 150px;"></div>

<style type="text/css">
    #result-table td {
        padding: 3px 1px 3px 2px;
        line-height: 20px;
        text-align: center;
    }
</style>

<script>
    Util.fillGames($(".f0 select"));
    $(".f2 input").datepicker({format: 'yyyy-mm-dd'});
    $(".f3 input").datepicker({format: 'yyyy-mm-dd'});
    var t = new Date().Format("yyyy-MM-dd");
    $(".f2 input").datepicker("setValue", t);
    $(".f3 input").datepicker("setValue", t);
    Util.restorePageFilter();

    var _f = Util.queryTemplate($("#result-table tbody"), ".zxf_pagediv", $(".button button"), function(page, size, cb) {
        var data = {
            pageNum: page,
            pageSize: size,
            refereeStat: 0,
        };
        var v = $(".f1 input").val().trim();
        if (v) data.uid = v;
        var v = $(".f2 input").val().trim();
        if (v) data.start = v;
        var v = $(".f3 input").val().trim();
        if (v) data.end = v;
        var v = $(".f0 select").val();
        if (v != -1) data.type = v;
        var v = $(".f4 input").val().trim();
        if (v) data.profitStart = v;
        var v = $(".f5 input").val().trim();
        if (v) data.profitEnd = v;

        if (data.end && data.start && 
            new Date(data.end).getTime() - new Date(data.start).getTime() > 31 * 24 * 3600 * 1000) {
            alert2("查询的时间跨度，不能超过一个月", true);
            return;
        }

        Util.savePageFilter([".f1 input", ".f2 input", ".f3 input", ".f0 select", ".f4 input", ".f5 input"]);
        startLoading();
        CMD.stat_user_squery(data, function(r) {
            stopLoading();
            cb(r);
        });
    }, function(table, list, sum) {
        if (Util.isEmpty(list)) {
            table.append("<tr><td colspan='17'>暂无数据</tr>");
            return;
        }

        // sum
        var tr = $("<tr></tr>");
        var d = sum;
        tr.append("<td colspan='5'>合计</td>");
        tr.append("<td>" + d.depositSum/100 + "</td>");
        tr.append("<td>" + d.withdrawSum/100 + "</td>");
        tr.append("<td>" + d.rewardSum/100 + "</td>");
        tr.append("<td>" + d.penaltySum/100 + "</td>");
        tr.append("<td>" + d.deductSum/100 + "</td>");
        tr.append("<td>" + d.depositCount + "/" + d.withdrawCount + "</td>");
        tr.append("<td>" + d.betSum/100 + "</td>");
        tr.append("<td>" + d.betCount + "</td>");
        tr.append("<td>" + d.betWin/100 + "</td>");
        if (d.betProfit >= 0)
            tr.append("<td class='red'>" + d.betProfit/100 + "</td>");
        else 
            tr.append("<td class='green'>" + d.betProfit/100 + "</td>");
        tr.append("<td>" + d.betBack/100 + "</td>");

        var v = (d.betProfit - d.betBack)/100;
        if (v >= 0)
            tr.append("<td class='red'>" + v + "</td>");
        else
            tr.append("<td class='green'>" + v + "</td>");
        tr.append("<td colspan='2'></td>");
        table.append(tr);

        for (var i in list) {
            var d = list[i];
            var user = d.user;
            var win = 0;
            var tr = $("<tr></tr>");
            var name = '<span class="gray">' + user.mobile + '</span>';
            if (d.online == 1)
                name = '<span class="blue">' + user.mobile + '</span>';
            tr.append("<td class='name'>" + name + "</td>");
            if (d.type == '')
                tr.append("<td>" + "全部游戏" + "</td>");
            else
                tr.append("<td>" + get_game_display_name(d.type) + "</td>");
                        
            tr.append("<td>" + (user.name || '') + "</td>");
            tr.append("<td>" + (user.referee || '') + "</td>");
            tr.append("<td>" + ((user.balance || 0)/100).toFixed(2) + "</td>");
            tr.append("<td>" + ((d.depositSum || 0)/100).toFixed(2) + "</td>");
            tr.append("<td>" + ((d.withdrawSum || 0)/100).toFixed(2) + "</td>");
            tr.append("<td>" + ((d.rewardSum || 0)/100).toFixed(2) + "</td>");
            tr.append("<td>" + ((d.penaltySum || 0)/100).toFixed(2) + "</td>");
            tr.append("<td>" + ((d.deductSum || 0)/100).toFixed(2) + "</td>");
            tr.append("<td>" + (d.depositCount || 0) + "/" + (d.withdrawCount || 0) + "</td>");

            var type = $(".f0 select").val();
            tr.append("<td>" + ((d.betSum || 0)/100).toFixed(2) + "</td>");
            tr.append("<td>" + ((d.betCount || 0)) + "</td>");
            tr.append("<td>" + ((d.betWin || 0)/100).toFixed(3) + "</td>");
            if (d.betProfit >= 0)
                tr.append("<td class='red'>" + ((d.betProfit || 0)/100).toFixed(3) + "</td>");
            else
                tr.append("<td class='green'>" + ((d.betProfit || 0)/100).toFixed(3) + "</td>");
            tr.append("<td>" + ((d.betBack || 0)/100).toFixed(2) + "</td>"); 
            win = (d.betProfit || 0) + (d.betBack || 0);
            if (win >= 0)
                tr.append("<td class='red'>" + ((win || 0)/100).toFixed(2) + "</td>");
            else
                tr.append("<td class='green'>" + ((win || 0)/100).toFixed(2) + "</td>");
            table.append(tr);
        }
    });

</script>
